package com.ys.nms.module.business.service.links;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.links.vo.*;
import com.ys.nms.module.business.dal.dataobject.links.LinksDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.links.LinksMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * 路线-自动 Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class LinksServiceImpl implements LinksService {

    @Resource
    private LinksMapper linksMapper;

    @Override
    public Integer createLinks(LinksSaveReqVO createReqVO) {
        // 插入
        LinksDO links = BeanUtils.toBean(createReqVO, LinksDO.class);
        linksMapper.insert(links);

        // 返回
        return links.getId();
    }

    @Override
    public void updateLinks(LinksSaveReqVO updateReqVO) {
        // 校验存在
        validateLinksExists(updateReqVO.getId());
        // 更新
        LinksDO updateObj = BeanUtils.toBean(updateReqVO, LinksDO.class);
        linksMapper.updateById(updateObj);
    }

    @Override
    public void deleteLinks(Integer id) {
        // 校验存在
        validateLinksExists(id);
        // 删除
        linksMapper.deleteById(id);
    }

    @Override
        public void deleteLinksListByIds(List<Integer> ids) {
        // 删除
        linksMapper.deleteByIds(ids);
        }


    private void validateLinksExists(Integer id) {
        if (linksMapper.selectById(id) == null) {
            throw exception(LINKS_NOT_EXISTS);
        }
    }

    @Override
    public LinksDO getLinks(Integer id) {
        return linksMapper.selectById(id);
    }

    @Override
    public PageResult<LinksDO> getLinksPage(LinksPageReqVO pageReqVO) {
        return linksMapper.selectPage(pageReqVO);
    }

}